﻿using LibNiconico.NiconicoApi.Extentions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;

namespace LibNiconico.NiconicoApi.Internal
{
    /// <summary>
    /// ニコニコスレッドコメント
    /// </summary>
    public abstract class NicoThreadCommentBase 
    {
        /// <summary>
        /// 結果コード
        /// </summary>
        public int ResultCode { get; set; }

        /// <summary>
        /// スレッド番号
        /// </summary>
        public string Thread { get; set; }

        /// <summary>
        /// スレッド受信時のコメント番号
        /// </summary>
        public int LastRes { get; set; }

        /// <summary>
        /// チケット
        /// </summary>
        public string Ticket { get; set; }

        /// <summary>
        /// リビジョン
        /// </summary>
        public int Revision { get; set; }

        /// <summary>
        /// サーバ時間
        /// </summary>
        public DateTime ServerTime { get; set; }

        /// <summary>
        /// コンストラクタ
        /// </summary>
        protected NicoThreadCommentBase()
        {
            ResultCode = 0;
            Thread = "";
            LastRes = 0;
            Ticket = "";
            Revision = 0;
            ServerTime = default(DateTime);
        }


        /// <summary>
        /// コメント解析
        /// </summary>
        /// <param name="threadComment"></param>
        /// <param name="message"></param>
        protected static void Parse(NicoThreadCommentBase threadComment, XElement message)
        {

            //
            //threadコメントのパース処理
            //

            threadComment.ResultCode = XElementExtention.GetAttributeAsInt(message,"resultcode");

            threadComment.Thread = XElementExtention.GetAttributeAsString(message,"thread");

            threadComment.LastRes = XElementExtention.GetAttributeAsInt(message,"last_res");

            threadComment.Ticket = XElementExtention.GetAttributeAsString(message,"ticket");
           
            threadComment.Revision = XElementExtention.GetAttributeAsInt(message,"revision");

            threadComment.ServerTime = DateTimeExtention.FromUnixTime(XElementExtention.GetAttributeAsLong(message, "server_time"));
                
            
        }

    }
}
